<!DOCTYPE html>
<html lang="zh-CN">

<head>
    {include file="public/header" /}
    <title>秒到3.0商户管理后台-添加商品</title>
    <link href="/public__STATIC__/admin/layui/css/layui.css?v={:date('ymd')}" rel="stylesheet" type="text/css" />
    <link href="/public__STATIC__/admin/layui/css/modules/code.css" rel="stylesheet" type="text/css" />
    <style>
        input[type="checkbox"]{
            margin-left: 8px;
        }
    </style>

</head>
<body class="page-header-fixed page-sidebar-closed-hide-logo page-content-white">
<div class="page-wrapper">
    {include file="public/navbar" /}
    <div class="clearfix"></div>
    <div class="page-container">
        {include file="public/sidebar" /}
        <div class="page-content-wrapper">
            <div class="page-content">
                <div class="row bordered">
                    <div class="col-md-8">
                        <div class="portlet light  relative">
                            <div class="portlet-title">
                                <div class="caption">
                                    <i class="icon-settings font-dark"></i><span class="caption-subject bold uppercase">配送设置</span></br>
                                    <span class="form-control-static pull-left zhushi margin-right">设置订单商品的配送方式和运费，并根据买家增加商品而追加运费</span>
                                </div>
                                <div class="actions">
                                    <div class="btn-group"></div>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <div class="box span12">
                                    <div class="box-content col-md-8  table-bordered table">
													<span class="form-control-static  margin-right">
														<img class="margin-right" src="/public__STATIC__/admin/image/u5338.png">
													</span>
										<span class="form-control-static zhushi margin-right"> <span style="font-size: 18px">到店自取</span></br>用户可以到指定门店自行取货
										</span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 col-xs-4 control-label"> <span class="required"> * </span>是否启用：</label>
                                <div class=" col-lg-4 col-xs-3">
                                    <div class="relative">
                                        <label class="radio-inline">
                                            <input type="radio" name="isService" value="1"/>
                                            是
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="isService"  value="2" />
                                            否</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    
                        <div class="portlet light  relative">
                            <div class="form-group">
                                <label class="col-lg-2 col-xs-4 control-label"> <span class="required">   * </span>适用门店：</label>
                                <div class="col-lg-6 col-xs-2">
                                            <input class="shop_type" type="radio" name="shop_type" value="1" checked  /><span >所有门店（以后新增的门店也将自动适用）</span></br>
                                            <input class="shop_type" type="radio" name="shop_type"  value="2" /><span >特定门店（未选中的门店不适用）</span>
                                </div>
                            </div>
                        </div>

                        <div class="portlet light  relative "  id="select_tenant">
                            <div class="form-group">
                                <label class="col-lg-2 col-xs-4 control-label"></label>
                                <div class="col-lg-3 col-xs-2 ">
                                    <select id="tenant" class="form-control border-radius" >
                                        <option value="1" selected>门店1</option>
                                        <option value="2">门店2</option>
                                        <option value="3">门店3</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="portlet light  relative "  id="select_tenant1">
                            <div class="form-group">

                                <label class="col-lg-2 col-xs-4 control-label"></label>

                                <div class="tenant_select_val ">

                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="page-footer">
    <div class="page-footer-inner">
        2017 &copy; 秒迅科技</a>
    </div>
    <div class="scroll-to-top">
        <i class="icon-arrow-up"></i>
    </div>
</div>
</div>
</body>
</html>

<script>
    $(function(){

        $(".shop_type").click(function(){


            $(".shop_type").removeAttr("checked");
            $(this).attr("checked",true);
            $(this).prop("checked",true);
            if($(this).val()==1){
                $("#select_tenant").hide();
            }else{
                $("#select_tenant").show();
            }
        });

        var $tenantArr = [];
        var valStr = "";

        $("#tenant").change(function(){
            var $tenantObj = {};
            var flag = true;
            var $_thisval = $("#tenant").val();
            $(this).find("option[value!="+$_thisval+"]").attr("selected",false);
            $("#tenant").find("option[value="+$_thisval+"]").attr("selected",true);
            var $_thistext = $("#tenant").find("option[value="+$_thisval+"]").text();

            $tenantObj.value=$_thisval;
            $tenantObj.text=$_thistext;
           for(var i = 0;i<$tenantArr.length;i++){
                if($tenantArr[i].value == $_thisval){
                    flag = false;
                }
            }
            if(flag){
                $tenantArr.push($tenantObj);
                var html = '<div class="table-bordered  text-muted  col-lg-3 col-xs-2" style="margin-left: 20px">'+
                        $_thistext+
                        '<i class="layui-icon  layui-col-md-offset3 store-class" store-id ="'+$_thisval+'">'+'&#x1006'+'</i>'
                '</div>'
                $(".tenant_select_val").append(html);
                console.log($tenantArr)
            }
            valStr = JSON.stringify($tenantArr)

            //test
            $(".tenant_select_val").find('.store-class').click(function(){
                 var storeId = $(this).attr('store-id');
                var reindex = "";

                $.each($tenantArr,function(index,el){
                    if(el.value == storeId){
                        reindex = index;
                        console.log(reindex)
                    }
                });

                $tenantArr.remove($tenantArr[reindex])
                console.log($tenantArr)
                $(this).parent().remove();
            });
        });

        /**
         *删除数组指定下标或指定对象
         */
        Array.prototype.indexOf = function(val) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == val) return i;
            }
            return -1;
        };

        Array.prototype.remove = function(val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };

    })
</script>